
*****************************************************************************
*********             Table 3 - Homogeneous Hedonic Price Function Estimates: Fixed Effects Models
*****************************************************************************
local cutoff=0.01
clear




// FULL SAMPLE NO RELIABILITY AND E(TT)




clear
save ".\data\temp\temp1", replace emptyok

* Get reliability
*I 10 W
use ".\data\clean\HV_ML_reliab", clear
keep if fwy==10&dir=="W"
format date %d
sort date hour
tempfile temp2
save `temp2'


use ".\data\clean\I10W_laneuse_dataset_15nov14_wcensus", clear

sort date hour
merge m:1 date hour using `temp2', keep(1 3) nogen 
drop if weekend==1
keep if inlist(hour,5,6,7,8)
drop if holiday==1

*WTP calculation
gen EL_TT=dist/ELspeed
gen ML_TT=dist/MLspeed
gen MP=inlist(hour,5,6,7,8)&weekend==0
gen TT_dif_hr=ML_TT-EL_TT
gen WTP2=charged_toll/TT_dif_hr



gen reliabilityML=dist/p20_speedML-dist/p50_speedML
gen reliabilityHV=dist/p20_speedHV-dist/p50_speedHV
gen reliability_diff=reliabilityML-reliabilityHV
replace reliability_diff=0 if reliability_diff<`cutoff'
keep if WTP2>0&WTP2~=.
keep if reliability_diff~=.
drop if TT_dif_hr==.
keep if acct_type=="PRIVATE"&occupancy~="HOV-3"
egen id=group(date rt_id)
egen tid=group(date hour rt_id)
egen acctid=group(acct_no)
duplicates drop acctid entry_time, force
xtset acctid entry_time


*******************************************************************************
***			 Column I --- Full Sample Homog. Agent 					*******
*******************************************************************************

keep if TT_dif_hr>0 
gen count=1
egen freq=sum(count), by(acct_no)
drop if freq<2
drop freq count
g fifteen=ceil(min/15)
egen ft=group(hour fifteen)

reg charged_toll TT_dif_hr reliability_diff if TT_dif_hr>0 , cluster(rt_id) 
est sto a2



xtreg charged_toll TT_dif_hr reliability_diff if TT_dif_hr>0   , robust fe 
est sto a3
predict fe_a3, u
replace fe_a3=fe_a3+_b[_cons]
qui sum fe_a3, det 
estadd scalar fe25=round(`r(p25)',.01)
estadd scalar femean=round(`r(mean)',.01)
estadd scalar fe75=round(`r(p75)',.01)

qui xi: xtreg charged_toll TT_dif_hr reliability_diff i.hour if TT_dif_hr>0   , robust fe 
est sto a4
predict fe_a4, u
replace fe_a4=fe_a4+_b[_cons]
qui sum fe_a4, det 
estadd scalar fe25=round(`r(p25)',.01)
estadd scalar femean=round(`r(mean)',.01)
estadd scalar fe75=round(`r(p75)',.01)
matrix B=e(b)
local dim `= colsof(B)'
local dim=`dim'-1
matrix C=B[.,3..`dim']
matrix C=C'
mata
	C = st_matrix("C")
	mean=mean(C)
	sd =  sqrt(variance(C))
	all=mean,sd
	st_matrix("all", all)
end
matlist all
local sdtime=all[1,2]
local meantime=all[1,1]
sum fe_a4
local sdacct=`r(sd)'
local meanacct=_b[_cons]+`r(mean)'
estadd scalar sdacct=`sdacct'
estadd scalar sdtime=`sdtime'

qui xi: xtreg charged_toll TT_dif_hr reliability_diff i.hour*i.dow if TT_dif_hr>0   , robust fe 
est sto a5
predict fe_a5, u
replace fe_a5=fe_a5+_b[_cons]
qui sum fe_a5, det 
estadd scalar fe25=round(`r(p25)',.01)
estadd scalar femean=round(`r(mean)',.01)
estadd scalar fe75=round(`r(p75)',.01)
matrix B=e(b)
local dim `= colsof(B)'
local dim=`dim'-1
matrix C=B[.,3..`dim']
matrix C=C'
mata
	C = st_matrix("C")
	mean=mean(C)
	sd =  sqrt(variance(C))
	all=mean,sd
	st_matrix("all", all)
end
matlist all
local sdtime=all[1,2]
local meantime=all[1,1]
sum fe_a5
local sdacct=`r(sd)'
local meanacct=_b[_cons]+`r(mean)'
estadd scalar sdacct=`sdacct'
estadd scalar sdtime=`sdtime'



qui xi: xtreg charged_toll TT_dif_hr reliability_diff i.dow*i.ft if TT_dif_hr>0 , robust fe
est sto a6
predict fe_a6, u
replace fe_a6=fe_a6+_b[_cons]
qui sum fe_a6, det 
estadd scalar fe25=round(`r(p25)',.01)
estadd scalar femean=round(`r(mean)',.01)
estadd scalar fe75=round(`r(p75)',.01)
matrix B=e(b)
local dim `= colsof(B)'
local dim=`dim'-1
matrix C=B[.,3..`dim']
matrix C=C'
mata
	C = st_matrix("C")
	mean=mean(C)
	sd =  sqrt(variance(C))
	all=mean,sd
	st_matrix("all", all)
end
matlist all
local sdtime=all[1,2]
local meantime=all[1,1]
sum fe_a6
local sdacct=`r(sd)'
local meanacct=_b[_cons]+`r(mean)'
estadd scalar sdacct=`sdacct'
estadd scalar sdtime=`sdtime'


qui xi: xtreg charged_toll TT_dif_hr reliability_diff i.dow*i.ft if TT_dif_hr>0 & date>td(20oct2013) ///
	, robust fe
est sto a7
predict fe_a7, u
replace fe_a7=fe_a7+_b[_cons]
qui sum fe_a7, det 
estadd scalar fe25=round(`r(p25)',.01)
estadd scalar femean=round(`r(mean)',.01)
estadd scalar fe75=round(`r(p75)',.01)
matrix B=e(b)
local dim `= colsof(B)'
local dim=`dim'-1
matrix C=B[.,3..`dim']
matrix C=C'
mata
	C = st_matrix("C")
	mean=mean(C)
	sd =  sqrt(variance(C))
	all=mean,sd
	st_matrix("all", all)
end
matlist all
local sdtime=all[1,2]
local meantime=all[1,1]
sum fe_a7
local sdacct=`r(sd)'
local meanacct=_b[_cons]+`r(mean)'
estadd scalar sdacct=`sdacct'
estadd scalar sdtime=`sdtime'






esttab  a2 a3 a4 a5 a6 a7 using ".\results\appendix\tabs\ATCXXXXXX.csv", replace  ///
	cells(b(star fmt(%9.3f)) se(par)) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2 N fe25 femean fe75 sdacct sdtime ,fmt(%9.2f %9.0g %9.2f %9.2f %9.2f %9.2f %9.2f) ///
		labels(R-squared N VOU_25 VOU_Mean VOU_75 VOU_sd_acct VOU_sd_time)) ///
	title("Table C.X--FE Models") drop(_I*) ///
	 nonumbers nodepvars  ///
	 order( _cons TT_dif_hr reliability_diff) label
 
